package com.bee.beemanage.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bee.beemanage.api.entity.SysDict;
import com.bee.beemanage.api.entity.output.Dict;
import com.bee.beemanage.api.mapper.SysDictMapper;
import com.bee.beemanage.api.service.SysDictService;
import com.bee.beemanage.system.common.utils.result.Result;
import com.bee.beemanage.system.common.utils.result.ResultTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author 陈国松
 * @since 2023-05-25
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    @Resource
    SysDictMapper sysDictMapper;
    /**
     * 分页获取字典码值及释义
     *
     * @param dictCode 字典码值
     * @return 码值:释义 列表
     */
    @Override
    public Page<Dict> pageGetDict(Page<Dict> page, String dictCode, String label,String value) {
        Page<Dict> result= new Page<>();
        //根据字典编码获取字典信息
        QueryWrapper<SysDict> query = Wrappers.query();
        query.eq("dict_code",dictCode);
        List<SysDict> sysDicts = sysDictMapper.selectList(query);
        if(null!=sysDicts&&sysDicts.size()==1){
            SysDict sysDict = sysDicts.get(0);
            result= sysDictMapper.getDictDetails(page,sysDict,label,value);
        }
        return result;
    }

    @Override
    public Page<SysDict> recycleSearch(Page<SysDict> page, SysDict sysDict, LocalDateTime startTime, LocalDateTime endTime) {
        return sysDictMapper.recycleSearch(page,sysDict,startTime,endTime);
    }

    @Override
    public boolean recover(List<String> idsList) {
        return sysDictMapper.recover(idsList);
    }

    @Override
    public Result clear() {
        Result result = ResultTool.success();
        sysDictMapper.clear();
        return result;
    }
}
